/**
 * 
 */
package com.googlecode.bestpaper.utils;

import java.io.IOException;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

/**
 * @author xalinx at gmail dot com
 * @date Jan 29, 2010
 */
public class ImageUtils {

	public static int[] getSize(String imageFormat, ImageInputStream iis)
			throws IOException {
		int width = 0;
		int height = 0;
		Iterator<ImageReader> imageReaders = ImageIO
				.getImageReadersByFormatName(imageFormat);
		if (imageReaders.hasNext()) {
			ImageReader imageReader = imageReaders.next();
			imageReader.setInput(iis);
			width = imageReader.getWidth(0);
			height = imageReader.getHeight(0);
			imageReader.dispose();
		}
		iis.close();

		return new int[] { width, height };
	}

}
